package jianzhiOffer;

public class test03 {
    public static int[] countBits(int n) {
        int[] s = new int[n+1];
        String temp = "";
        for(int i =0;i<=n;i++){
            temp = Integer.toBinaryString(i);
            int j=temp.length()-1;
            int count=0;
            while(j>=0){
                count += (temp.charAt(j)=='1'?1:0);
                j--;
            }
            s[i]=count;
        }
        return s;
    }

    public static void main(String[] args) {
        countBits(3);
    }
}
